/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.barrientosjunior.blackup.action;

import br.com.barrientosjunior.blackup.MainManager;
import br.com.barrientosjunior.blackup.model.File;
import br.com.barrientosjunior.utils.Files;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Junior
 */
public class ExecuteRecoverBackupAction implements Runnable{
    MainManager manager = null;
    File file = null;

    public ExecuteRecoverBackupAction(MainManager manager, File file) {
        this.manager = manager;
        this.file = file;
    }

    public void execute() throws IOException {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("Selecione o destino de recuperação do backup:");
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        int retVal = fileChooser.showDialog(manager.getMainFrame(), "Selecionar");
        java.io.File recoverFile = null;
        if (retVal == 0){
                recoverFile = fileChooser.getSelectedFile();
                Files.copyFile(new java.io.File(file.getPathDestiny()), recoverFile);
                manager.getMainFrame().getjLabelStatusValue().setText("Recuperação terminada.");
        } else {
            manager.getMainFrame().getjLabelStatusValue().setText("Recuperação interrompida.");
        }

    }

    public void run(){
        try {
            this.execute();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(manager.getMainFrame(),
                    ex.getMessage(),
                    "Erro de reuperação de backup",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

}
